home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicDesktopManager.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  138 lines

  1. /*
  2.  * @(#)OrganicDesktopManager.java    1.3 98/02/05
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import java.awt.*;
  24. import java.beans.*;
  25. import com.sun.java.swing.*;
  26. import java.util.*;
  27.  
  28. /** This is an extension of the DefaultDesktopManager. 
  29.   * It helps implement the Organic desktop management scheme.  It is mostly concerned
  30.   * with iconization and deiconization of internal frames
  31.   *
  32.   * @see DefaultDesktopManager
  33.   * @see OrganicDesktopPaneUI
  34.   * @see OrganicDesktopMenu
  35.   * @version 1.3 02/05/98
  36.   * @author Steve Wilson
  37.   */
  38. public class OrganicDesktopManager extends DefaultDesktopManager {
  39.  
  40.     Vector iconizedWindows = new Vector();
  41.     Container theDesktop;
  42.     OrganicDesktopPaneUI desktopUI;
  43.  
  44.     /** Removes the frame from it's parent and stores it for later use. 
  45.       */
  46.     public void iconifyFrame(JInternalFrame f) {
  47.  
  48.         theDesktop.remove(f);
  49.         iconizedWindows.addElement(f);
  50.  
  51.         theDesktop.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
  52.         try { f.setSelected(false); } catch (PropertyVetoException e2) { }
  53.     desktopUI.frameIconified();
  54.     
  55.     }
  56.  
  57.     /** replaces the frame in  the parent and removed it from the iconizedWindowList
  58.       */
  59.     public void deiconifyFrame(JInternalFrame f) {
  60.  
  61.     iconizedWindows.removeElement(f);
  62.     try  {f.setIcon(false);} catch (PropertyVetoException e2) { }
  63.     theDesktop.add(f);
  64.         try { f.setSelected(true); } catch (PropertyVetoException e2) { }
  65.     desktopUI.frameDeiconified();
  66.  
  67.     }
  68.  
  69.     /** this function puts a DesktopIcon back into the frame
  70.      * this function is used when switching from Organic to another Look & Feel
  71.      * it is called by OrganicDesktopPaneUI.replaceDesktopIcons
  72.      */
  73.     protected void replaceDesktopIcon(JInternalFrame.JDesktopIcon icon) {
  74.         Rectangle iconBounds = icon.getBounds();
  75.     JInternalFrame f = icon.getInternalFrame();
  76.     theDesktop.add(icon);
  77.         if (iconBounds.equals( new Rectangle(0,0,0,0) )) {
  78.         Rectangle r = getBoundsForIconOf(f);
  79.         icon.setBounds(r.x, r.y, r.width, r.height);
  80.         setWasIcon(f, Boolean.TRUE);
  81.     } // end if
  82.  
  83.     }
  84.  
  85.     /**
  86.       * returns the list of iconized windows.
  87.       * in Organic these windows will appear in the small menu in the top-right corner
  88.       */
  89.     public Vector getIconizedWindows() {
  90.         return iconizedWindows;
  91.     }
  92.     
  93.     /**
  94.      * This function takes a JDesktopIcon and adds it to the list of iconized windows
  95.      * it is called by OrganicDesktopPaneUI.removeDesktopIcons()
  96.      */
  97.     public void addToIconizedWindowList(JInternalFrame.JDesktopIcon icon) {
  98.         iconizedWindows.addElement(icon.getInternalFrame());
  99.     }
  100.  
  101.     /**
  102.       * this function takes the Container which will contain the InternalFrames
  103.       * this should usually be a JDesktopPane
  104.       */
  105.     public void setTheDesktop(Container c) {
  106.         theDesktop = c;
  107.     }  
  108.  
  109.     public void setDesktopUI(OrganicDesktopPaneUI ui) {
  110.         desktopUI = ui;
  111.     }  
  112.  
  113.     /**
  114.       * this is an override of a function from BasicDesktopManager
  115.       * it works around a bug in the current implementation
  116.       * this may be removed later, but we might still want to keep our own
  117.       * this function is called by OrganicDesktopManager.replaceIcon()
  118.       */
  119.     protected Rectangle getBoundsForIconOf(JInternalFrame f) {
  120.  
  121.         Dimension prefSize = f.getDesktopIcon().getPreferredSize();
  122.         int x2, y2, w2, h2;
  123.  
  124.         w2 = prefSize.width;
  125.         h2 = prefSize.height;
  126.         x2 = 0;
  127.         y2 = theDesktop.getSize().height - h2;
  128.  
  129.         return  new Rectangle(x2, y2, w2, h2);
  130.     }
  131.  
  132.     public void deactivateFrame(JInternalFrame f) {
  133.         f.repaint(); // this is inefficient.  should just redraw border?
  134.     }
  135.  
  136. }
  137.  
  138.